{% extends 'base.html' %}
{% block title %}Brisbane Coupon{% endblock %}
{% block stylesheet %}
{{ block.super }}
{% endblock%}

{% block javascript %}
{{ block.super }}
<script type="text/javascript">
$(document).ready(function(){
    {% if not user.is_authenticated %}
    tkstickyMsg("You can get this coupon after logging in", "info");
    {% endif %}
	$("body").click(function(event) {
        if ($(event.target).is(".couponBtn")) {
        	
            {% if not user.is_authenticated %}
            tkstickyMsg("You can get this coupon after logging in", "info");
            return false;   
            {% endif %}
            
            var couponId = $(event.target).attr("id");
            var leftCoupon = $("#leftCoupon").text().split("/")[0]
            var totalCoupon = $("#leftCoupon").text().split("/")[1]

            if (leftCoupon == 0) {
            	tkstickyMsg("No more Coupon", "Bad");
            	return false;
            }
            
            {% if local_test %}
            var address = 'http://localhost:8000/coupon/sms/' + couponId + '/' + {{ user.id }} + '/';
            {% else %}
            var address = 'http://brisbanecoupon.com/coupon/sms/' + couponId + '/' + {{ user.id }} + '/';
            {% endif  %}
            
            tkstickyMsg("Sending....", "good");
            
            $.ajax({
                 url:address,
                 dataType: 'jsonp',
                 success:function(data){
                    if(data.result.success == true) {
                        tkstickyMsg(data.result.msg, "good");
                        tkstickyMsg("{{ event.coupon.textmsg }}", "good");
                        leftCoupon = leftCoupon - 1;
                        $("#leftCoupon").text(leftCoupon.toString() + "/" + totalCoupon);
                    } else {
                       tkstickyMsg(data.result.msg, "good");
                    }
                 },
                 error:function(){
                     alert('Something went wrong');
                 },
            });
            
            /*
            $.get(address, function(data){
                if(data.result.success == true) {
                    tkstickyMsg(data.result.msg, "good");
                    tkstickyMsg(msg, "good");
                    leftCoupon = leftCoupon - 1
                    $("#leftCoupon").text(leftCoupon.toString() + "/" + totalCoupon);
                } else {
                    tkstickyMsg(data.result.msg, "good");
                }
            }).complete(function(){
            });
            */
            return false;
        }
    });
});
</script>
{% endblock%}

{% block content %}
{% load thumbnail %}

<div id="fb-root"></div>
<script>(function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) return;
  js = d.createElement(s); js.id = id;
  js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>

<div id="dRightAdLayout">
  <div id="dRightAd">
    <div class="cCircle">
    </div>
    <span class="cRightTitle">유사이벤트</span>
    <div id="dRightAdin">
      <ul>
        {% for s in event.get_similar_events %}
        <li><a href="{{ s.url }}">{{ s.name }}</a></li>
        {% empty %}
        <li><a href="#">유사이벤트가 없습니다</a></li>
        {% endfor %}
      </ul>
    </div> <!-- dRightAdin -->
  </div> <!-- dRightAd -->
  <br>
  <div id="dRightAd">
    <div class="cCircle">
    </div>
    <span class="cRightTitle">유사가게</span>
    <div id="dRightAdin">
      <ul>
        {% for s in event.get_similar_stores %}
        <li><a href="{{ s.url }}">{{ s.name }}</a></li>
        {% empty %}
        <li><a href="#">유사가게가 없습니다</a></li>
        {% endfor %}
      </ul>
    </div> <!-- dRightAdin -->
  </div> <!-- dRightAd -->
  <br>
  <div id="dRightAd">
    <div class="cCircle">
    </div>
    <span class="cRightTitle">근처가게(주변3km)</span>
    <div id="dRightAdin">
      <ul>
        {% for s in event.store.get_near_stores %}
        <li><a href="{{ s.url }}">{{ s.name }}</a></li>
        {% empty %}
        <li><a href="#">근처가게가 없습니다</a></li>
        {% endfor %}
      </ul>
    </div> <!-- dRightAdin -->
  </div> <!-- dRightAd -->
</div> <!-- dRightAdLayout -->

<div id="dWrapper">
  <div id="dEventTitle">
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="45%"><h1><a href="{{ event.url }}">{{ event.name }}</a></h1></td>
        <td width="20%"><strong>{{ event.sdate|date:"D d M" }} - {{ event.edate|date:"D d M" }}</strong></td>
        <td class="cEventsDetail">
          <span id="dStore"><a href="{{ event.store.url }}">{{ event.store.name }}</a></span>
          <span class="cSmall">{{ event.store.addr }}</span>
        </td>
        <td width="10%"><fb:like expr:href='data:post.url' font='' layout='button_count' send='true' show_faces='false' width='450' colorscheme='light'></fb:like></tr>
      </tr>
    </table>
  </div>

  <div id="dLineContent">
    <div id="dEventDes">
      {{ event.description|safe }}
      <div class="cDowncoupon">
        {% if not event.get_coupon_status %}
        <a href="#">쿠폰이 없는 이벤트입니다.</a>
        {% else %}
        {% ifequal event.get_coupon_status "PAST" %}
        <a href="#">이벤트 기간이 끝났습니다.</a>
        {% else %}
        <a class="couponBtn" href="#" id="{{ event.coupon.id }}">모바일쿠폰받기<span class="cLeftcoupon"><span id="leftCoupon" class="cLeftNumber">{{ event.get_coupon_status }}</span></span></a>
        {% endifequal %}
        {% endif %}
      </div>
    </div>
  </div>


  <div id="dStoreTitle">
    <h2 class="cGallery">Gallery</h2>
  </div>
  <div id="dLineContent">
    {% thumbnail event.detail "800x200" as im %}
    <img src="{{ im.url }}">
    {% endthumbnail %}
    
    {% if event.image1 %}
    {% thumbnail event.image1 "700x400" as im %}
    <img src="{{ im.url }}">
    {% endthumbnail %}
    {% endif %}
  
    {% if event.image2 %}
    {% thumbnail event.image2 "700x400" as im %}
    <img src="{{ im.url }}">
    {% endthumbnail %}
    {% endif %}
  
    {% if event.image3 %}
    {% thumbnail event.image3 "700x400" as im %}
    <img src="{{ im.url }}">
    {% endthumbnail %}
    {% endif %}
  
    {% if event.image4 %}
    {% thumbnail event.image4 "700x400" as im %}
    <img src="{{ im.url }}">
    {% endthumbnail %}
    {% endif %}
  
    {% if event.image5 %}
    {% thumbnail event.image5 "700x400" as im %}
    <img src="{{ im.url }}">
    {% endthumbnail %}
    {% endif %}
    
    {% if event.image6 %}
    {% thumbnail event.image6 "700x400" as im %}
    <img src="{{ im.url }}">
    {% endthumbnail %}
    {% endif %}
  
    {% if event.image7 %}
    {% thumbnail event.image7 "700x400" as im %}
    <img src="{{ im.url }}">
    {% endthumbnail %}
    {% endif %}
  
    {% if event.image8 %}    
    {% thumbnail event.image8 "700x400" as im %}
    <img src="{{ im.url }}">
    {% endthumbnail %}
    {% endif %}
  
    {% if event.image9 %}
    {% thumbnail event.image9 "700x400" as im %}
    <img src="{{ im.url }}">
    {% endthumbnail %}
    {% endif %}
  
    {% if event.image10 %}
    {% thumbnail event.image10 "700x400" as im %}
    <img src="{{ im.url }}">
    {% endthumbnail %}
    {% endif %}
  </div>
  <div class="fb-comments" data-href="{{ full_path }}" data-num-posts="5" data-width="800"></div>
</div>

{% endblock %}
